package be.ipl.finito.daoimpl;

import java.util.HashSet;
import java.util.Set;

import javax.ejb.Stateless;

import be.ipl.finito.dao.ParticipationDao;
import be.ipl.finito.domaine.Jeton;
import be.ipl.finito.domaine.Participation;
import be.ipl.finito.domaine.Partie;

@SuppressWarnings("serial")
@Stateless
public class ParticipationDaoImpl extends DaoImpl<Integer, Participation>
		implements ParticipationDao {

	@Override
	public Participation rechercher(int id) {
		Participation part = super.rechercher(id);
		Set<Jeton> jetons = new HashSet<Jeton>();
		Partie p = part.getPartie();
		for (int i = 1; i < (p.getPositionTirage()); i++) {
			jetons.add(p.getTirage(i));
		}
		for (Jeton jeton : part.getCases()) {
			jetons.remove(jeton);
		}

		part.setJetonAPlacer(jetons);
		return part;
	}

}
